﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ICSharpCode.Core;

namespace Draco.OWF.Designer.Host
{
    public class EnvSetting
    {
        public static bool CheckEnvPath()
        {
            //Check OWF engine root path 
            String path = PropertyService.Get<String>(Constants.KEY_OWF_ENGINE_ENV_ROOT_PATH,"");
            if (String.IsNullOrWhiteSpace(path))
            {
                MessageService.ShowWarning(Constants.MSG_OWF_ENGINE_ENV_ROOT_NOT_SEPECIFIED);
                return false;
            }
            if (path.StartsWith("%") && path.EndsWith("%"))
            {
                String realpath = System.Environment.GetEnvironmentVariable(path);
                if (String.IsNullOrWhiteSpace(realpath))
                {
                    MessageService.ShowWarningFormatted(Constants.MSG_OWF_ENGINE_ENV_ROOT_UNKNOW_VAR, path);
                    return false;
                }
                path = realpath;
            }
            if (!System.IO.Directory.Exists(path))
            {
                MessageService.ShowWarningFormatted(Constants.MSG_OWF_ENGINE_ENV_ROOT_NOT_EXIST, path);
                return false;
            }
            return true;
        }

        public static String ENV_PATH
        {
            get
            { 
                String path = PropertyService.Get<String>(Constants.KEY_OWF_ENGINE_ENV_ROOT_PATH,"");
                if (!String.IsNullOrWhiteSpace(path))
                {
                    if (path.StartsWith("%") && path.EndsWith("%"))
                    {
                        path = System.Environment.GetEnvironmentVariable(path);
                    }
                    if (!String.IsNullOrWhiteSpace(path) && System.IO.Directory.Exists(path))
                    {
                        return path;
                    }
                }
                return "";
            }
        }
    }
}
